package com.yukong.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;

/**
 * Description:
 * User: xp
 * Date: 2018-01-04
 * Time: 14:26
 */
//@Component
@Aspect
public class TimerAspect {

    @Pointcut("execution (* com.yukong.web.controller.UserController.*(..))")
    public void  pointCut(){}

    @Around(value = "pointCut()")
    public Object  handleControllerMethod(ProceedingJoinPoint point) throws Throwable {
        System.out.println("time aspect start");

        Arrays.stream(point.getArgs()).forEach(e->System.out.println("arg is: " + e));

        long start = new Date().getTime();

        Object obj = point.proceed();

        System.out.println("time aspect 耗时:" + (new Date().getTime()-start)+"ms");
        System.out.println("time aspect end");

        return obj;
    }

}
